﻿CREATE PROCEDURE [dbo].[proc_Order_Getlist_Claim]
	(
		@CompanyId int,
		@StateId int,
		@Stext nvarchar(50),
		@StartIndex int,
		@EndIndex int
	)
AS
Begin
	;WITH list As(Select top 200 ROW_NUMBER() OVER (ORDER BY CreateDate DESC)AS Row
		,Id
		,OId
		,IsNull(OrderId,'') As OrderId
		,CusId
		,CusName
		,CusPerson
		,CusPersonTel
		,CusDescription
		,CusEstimate
		,TypeId
		,TypeName
		,WayId
		,WayName
		,ProcessId
		,ProcessName
		,Salesman
		,SalesmanAccount
		,TradeDate
		,CreateDate
		,YingShouPrice
		,ShiShouPrice
		,Discount
		,PaymentTypeId
		,PaymentType
		,BankId
		,Bank
		,PaymentDescription
		,OtherDescription
		,DepId
		,CompanyId
		,StateId,flag
,NOE_Flag
		,IsNULL((Select Title From Order_State Where Id=[Order].StateId),'...') As StateName
		,(Select Id From Order_PaymentRecord Where OId=[Order].OId And SWId=1) As PayRecordId
		From [Order]
		Where (@CompanyId=0 Or CompanyId=@CompanyId) And (@StateId=0 Or StateId=@StateId Or flag=1) And (@Stext='' Or CusName like '%'+@Stext+'%' Or Salesman like '%'+@Stext+'%')
	)
	
	Select *,(SELECT COUNT(1) FROM list) AS cid From list  Where Row Between @StartIndex and @EndIndex Order By Row
End
